//
//  BaseTabbarController.m
//  RadioBroadcastingStation
//
//  Created by ytkjs2 on 2019/5/5.
//  Copyright © 2019年 ytk. All rights reserved.
//

#import "BaseTabbarController.h"
#import "MyNavigationController.h"
#import "BaseTabBar.h"
#import "MainViewController.h"
#import "CarefullyChosenController.h"
#import "LoversViewController.h"
#import "SettingViewController.h"


@interface BaseTabbarController ()<UITabBarControllerDelegate>
@property (nonatomic,strong)UIButton * button;
@end

@implementation BaseTabbarController
@synthesize button;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.delegate=self;
    self.tabBar.barTintColor = RGB(1, 1, 1, 1);
    [self.tabBar setShadowImage:[UIImage new]];
    [self.tabBar setBackgroundImage:[UIImage new]];
    [self.tabBar setBackgroundColor:RGB(1, 1, 1, 1)];
//    [self setup];
    
    
//    [self createTabbar];
    [self setupTabbarTextConfig];
    [self setTabBarVC];
}

-(void)createTabbar{
    
    BaseTabBar *tabbar =[[BaseTabBar alloc] init];
    [self setValue:tabbar forKey:@"tabBar"];
}

-(void)setupTabbarTextConfig{
    
    NSMutableDictionary *attrus =[NSMutableDictionary dictionary];
    attrus[NSFontAttributeName] =[UIFont systemFontOfSize:12];
    attrus[NSForegroundColorAttributeName] =[UIColor lightGrayColor];
    
    NSMutableDictionary *selectAttrus =[NSMutableDictionary dictionary];
    selectAttrus[NSForegroundColorAttributeName] =[UIColor blackColor];
    
    UITabBarItem *item =[UITabBarItem appearance];
    [item setTitleTextAttributes:attrus forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectAttrus forState:UIControlStateSelected];
    
    //设置背景图片
    //    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
    [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
    //去除 TabBar 自带的顶部阴影  去掉顶部黑线
    [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
}


/*
#pragma mark --中间按钮点击事件

-(void)pressChange:(id)sender
{
    PlayerViewController * playVC = [[PlayerViewController alloc]initWithNibName:@"PlayerViewController" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:playVC animated:YES];
}
 */


#pragma mark- TabBar Delegate

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(nonnull UIViewController *)viewController
{
    return YES;
}

// 初始化所有子控制器
- (void)setTabBarVC{
    
    [self setTabBarChildController: [[MainViewController alloc]initWithNibName:@"MainViewController" bundle:[NSBundle mainBundle]] title:@"斗图表情" image:@"icon_main_noSel" selectImage:@"icon_main_sel"];
    
    [self setTabBarChildController: [[CarefullyChosenController alloc]initWithNibName:@"CarefullyChosenController" bundle:[NSBundle mainBundle]] title:@"精选壁纸" image:@"icon_care_noSel" selectImage:@"icon_care_sel"];
    
    [self setTabBarChildController: [[LoversViewController alloc]initWithNibName:@"LoversViewController" bundle:[NSBundle mainBundle]] title:@"情侣套图" image:@"icon_love_noSel" selectImage:@"icon_love_sel"];
    
    [self setTabBarChildController: [[SettingViewController alloc]initWithNibName:@"SettingViewController" bundle:[NSBundle mainBundle]] title:@"设置" image:@"icon_setting_noSel" selectImage:@"icon_setting_sel"];
}


// 添加tabbar的子viewcontroller
- (void)setTabBarChildController:(UIViewController*)controller title:(NSString*)title image:(NSString*)imageStr selectImage:(NSString*)selectImageStr{
    
    MyNavigationController* nav = [[MyNavigationController alloc] initWithRootViewController:controller];
    
    nav.tabBarItem.title = title;
    
    nav.tabBarItem.image = [[UIImage imageNamed:imageStr]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    nav.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageStr]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [nav.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11],NSForegroundColorAttributeName:RGB(194, 194, 194, 1)} forState:UIControlStateNormal];
    [nav.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11],NSForegroundColorAttributeName:APP_THEME_COLOR} forState:UIControlStateSelected];
    
    [self addChildViewController:nav];
    
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
